  package edu.hawaii.duedates.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import edu.hawaii.duedates.BookInfoRecord;

/**
 * The unit test for BookInfoRecord, which will check for accuracy with the date and book titles.
 * 
 * @author Daniel Arakaki, John Ancheta, Mari-Lee Flestado
 */
public class TestBookInfoRecord {

  /** An arrayList to hold pertinent information regarding the due date. */
  List<BookInfoRecord> bookList = new ArrayList<BookInfoRecord>();
  
  /**
   * The constructor instantiates objects and fills an array list for testing.
   */
  @Before
  public void setUp() {
    Date aDate = new Date();
    String bookTitle = "ABC";
    bookList.add(new BookInfoRecord(aDate, bookTitle, "uhm"));
  }

  /**
   * Testing for getting a due date.
   */
  @Test
  public void testGetDueDate() {
    Date testDate = new Date();
    Date aDate = bookList.get(0).getDueDate();
    assertEquals("Testing the getDueDate method: ", testDate.toString() ,aDate.toString());
  }

  /**
   * Testing for getting a book title.
   */
  @Test
  public void testGetBookTitle() {
    String bookTitle = "";
    bookTitle = bookList.get(0).getBookTitle();
    assertEquals("Testing the getBookTitle method: ", "ABC", bookTitle);
  }
  
  /**
   * Testing the testGetLibrary method.
   */
  @Test
  public void testGetLibrary() {
    String libraryCode = "";
    libraryCode = bookList.get(0).getLibrary();
    assertEquals("Testing the getLibrary method: ", "uhm", libraryCode);
  }

  /**
   * Testing the equals method.
   */
  @Test
  public void testEquals() {
    boolean equalsFlag = false;
    for (BookInfoRecord bookInfo : bookList) {
      equalsFlag = bookInfo.equals(bookInfo);
    }
    assertEquals("Testing the comparision of dates", true, equalsFlag);
  }
  
  /**
   * Testing the equals method with Integer.
   */
  @Test
  public void testEqualsWithInteger() {
    BookInfoRecord bookInfoRecord = new BookInfoRecord(new Date(), "bookTitle", "librarycode");
    String s = "some string";
    assertFalse("Testing non equal comparision.", bookInfoRecord.equals(s));
  }
  
  /**
   * Testing the equals method with two different BookInfoRecords.
   */
  @Test
  public void testEqualsWithTwoBookRecords() {
    BookInfoRecord bookInfoRecord = new BookInfoRecord(new Date(), 
                                                       "bookTitle", 
                                                       "librarycode");
    BookInfoRecord otherBookInfoRecord = new BookInfoRecord(new Date(), 
                                                           "otherBookTitle",
                                                           "otherLibrarycode");
    assertFalse("Testing for equal comparision.", 
                bookInfoRecord.equals(otherBookInfoRecord));
  }

  /**
   * Testing the hashCode method.
   */
  @Test
  public void testHashCode() {
    int hashFlag = 0;
    int hashFlagTwo = 0;
    for (BookInfoRecord bookInfo : bookList) {
      hashFlag = bookInfo.hashCode();
      hashFlagTwo = bookInfo.hashCode();
    }
    assertEquals("Testing the comparision of dates", hashFlag, hashFlagTwo);
  }

  /**
   * Testing the compareTo method.
   */
  public void testCompareTo() {
    //make sure its not zero
    int flag = 1;
  
    for (BookInfoRecord bookInfo : bookList) {
      flag = bookInfo.compareTo(bookInfo);
    }
    assertEquals("Testing the comparison of dates", 0, flag);
  }

}
